package com.spring.sunflower.common

import com.spring.sunflower.base.BaseObserver
import com.spring.sunflower.base.BasePresenter
import com.spring.sunflower.bean.SignInBean
import com.spring.sunflower.bean.TaskBean

/**
 * Created by Kevin on 2021/8/24<br/>
 *
 * Describe:<br/>
 */
class TaskPresenter(baseView: CommonContract.TaskView) :
    BasePresenter<CommonContract.TaskView>(baseView) {
    fun getTask() {
        val observable =
            requestDataSource.queryTask()
        addDisposable(observable, object : BaseObserver<TaskBean>() {
            override fun onSuccess(bean: TaskBean?) {
                baseView.showTaskList(bean!!.datas)
            }

            override fun onError(status: Int, msg: String?) {
            }
        })
    }

    fun signIn() {
        val observable =
            requestDataSource.signIn()
        addDisposable(observable, object : BaseObserver<SignInBean>(baseView) {
            override fun onSuccess(bean: SignInBean?) {
                baseView.signSuccess(bean!!.datas)
            }

            override fun onError(status: Int, msg: String?) {
            }
        })
    }

    fun querySignInRecord() {
        val observable =
            requestDataSource.querySignInRecord()
        addDisposable(observable, object : BaseObserver<SignInBean>() {
            override fun onSuccess(bean: SignInBean?) {
                if (bean!!.datas != null) {
                    baseView.signSuccess(bean!!.datas)
                } else {
                    baseView.noSign()
                }
            }

            override fun onError(status: Int, msg: String?) {
            }
        })
    }
}